﻿using CatUtils.Utils.Currency.TextUtils;

using CatUtils.Utils.SpecialUtils.Html;
using CatUtils.Utils.SpecialUtils.View;
using CatUtilsDll.Utils.Currency.WebUtils;
using RabbitDownload.Helper;
using RabbitDownload.Helper.Currency;
using RabbitDownload.Helper.ViewHelper;
using System;

namespace RabbitDownload.WebSite.Zerochan
{
    internal class ZerochanLogin
    {
        /// <summary>
        /// 发送登录请求
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="UserPass"></param>
        /// <returns></returns>
        public bool SendPost(string UserName, string UserPass, bool AlertFlag = false)
        {
            if (UserName == "" || UserPass == "")
            {
                Console.WriteLine("用户名或密码为空，不登录。");
                return false;
            }

            string API = "https://www.zerochan.net/login";
            string Mode = "ref=%2F&name={0}&password={1}&login=Login";
            String PostData = string.Format(Mode,
                 WebHelper.UrlEncode(UserName),
                 WebHelper.UrlEncode(UserPass)
                );

            string Shtml = StaticValueOld.CookiesWebclient.SendPost(API, PostData, WebHelper.PcWebHeader());

            if (HtmlHelper.GetFirstHtml(Shtml, "//div[@id='header']/ul").IndexOf("<li>Logged in as") >= 0)
            {
                Console.WriteLine("登陆成功");
                if (AlertFlag)
                    MessageHelper.Alert("登陆成功");
                return true;
            }
            Console.WriteLine("登录失败");
            if (AlertFlag)
                MessageHelper.Alert("登录失败");
            return false;
        }
    }
}